package com.zhang.spark_1.spark_core.operator.transform

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

/**
 * @title:
 * @author: zhang
 * @date: 2021/12/5 18:51 
 */
object Spark01_RDD_Operator_Transform {

  def main(args: Array[String]): Unit = {
    //获取spark的连接
    val conf: SparkConf = new SparkConf().setMaster("local[*]").setAppName("operator")
    val sc: SparkContext = new SparkContext(conf)
    //TODO map算子
    val rdd: RDD[Int] = sc.makeRDD(List(1, 2, 3, 4))
    def mapFunction(num:Int):Int={
      num*2
    }
    //val mapRDD: RDD[Int] = rdd.map((num: Int) => num * 2)
    //val mapRDD: RDD[Int] = rdd.map(_ * 2)
    val mapRDD: RDD[Int] = rdd.map(mapFunction)
    mapRDD.collect().foreach(println)
    sc.stop()
  }
}
